#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "highdata.h"
#include <unistd.h>
#include "dt_ctl_plus.h"

#define dbg printf


//void print_array(uint8_t *a, uint16_t len) {
//    uint16_t i = 0;
//    for(i = 0; i <len; i++) {
//        printf("%02d ", a[i]);
//    }
//    printf("\r\n");
//}

static void _run_handle(void) {
    static int32_t t = 0;
    dsta.execute_pe = KSMOOTH_COMM(dsta.sample_pe, 5);
    //dsta.execute_pe = KFILTER_COMM(dsta.sample_pe, 5);
    if((t++)%5 == 0) {
        dt_plus_handle(dsta.execute_pe);
    }
}

int main(int argc, char** argv) {
    static uint8_t wcnt = 0;
	int uartx = 7;
	if(argc > 1) {
		uartx = atoi(argv[1]);
	}
    dt_plus_default();
    dbg("uartx = %d\r\n", uartx);
    while(1) {
        virtual_pe_handle();
        dsta.sample_pe = virtual_pe;
        _run_handle();
        remote_dump_send(uartx);

        if(wcnt == 99) {
            usleep(100*1000);
            //usleep(5000*1000);
        }
        
        if(wcnt < 99) {
            wcnt++;
        }else {
            wcnt = 0;
        }
    }
    return 0;
}

